<template>
  <section class="">
    <div class="chapter border-bottom d-flex align-items-center">
      <h2 class="flex-1 border-right text-center" @click.stop="prev">上一章</h2>
      <h2 class="flex-1  text-center" @click.stop="next">下一章</h2>
    </div>
    <div class="menu d-flex align-items-center">
      <router-link :to="'/books/chapter/' + bookId" tag="div" class="item flex-1 d-flex flex-1 align-items-center justify-content-center flex-direction-column">
        <i class="iconfont icon-mulu"></i>
        <p>目录</p>
      </router-link>
      <div class="item flex-1 d-flex flex-1 align-items-center justify-content-center flex-direction-column" @click.stop="showSetting">
        <i class="iconfont icon-shezhi1"></i>
        <p>设置</p>
      </div>
      <router-link tag="div" :to="'/books/discuss/'+bookId+'/list'" class="item flex-1 d-flex flex-1 align-items-center justify-content-center flex-direction-column">
        <i class="iconfont icon-taolun-"></i>
        <p>评论</p>
      </router-link>
    </div>
  </section>
</template>

<script>
import bus from 'utils/EventBus'

import {show} from 'utils/Base'

export default {
  name: 'ReaderBottom',
  props: {
    bookId: String
  },
  data () {
    return {
      lastChapterId: 0,
      nextChapterId: 0
    }
  },
  methods: {
    showSetting () {
      bus.$emit('notifySettingShow');
      this.$emit('notifyHideToolbar');
    },
    prev () {
      if(this.lastChapterId == 0)  {
        show('当前已经是第一章');
        return
      }
      this.$router.replace(`/books/reader/${this.bookId}/${this.lastChapterId}`);
    },
    next () {
      if(this.nextChapterId == 0)  {
        show('当前已经是最后一章');
        return
      }
      this.$router.replace(`/books/reader/${this.bookId}/${this.nextChapterId}`);
    }
  },
  created () {
    bus.$on('sendChapterId', (lastChapterId, nextChapterId) => {
      this.lastChapterId = lastChapterId
      this.nextChapterId = nextChapterId
    })
  }
}
</script>

<style lang="stylus" scoped>
section {
  background #000
  color #FFF
  height $toolbar-height * 2
  padding 0 3vw
  position fixed 
  bottom 0
  left 0
  right 0
  z-index 9999

  .menu,
  .chapter {
    height 50%
    position absolute 
    left 0
    right 0
  }

  .chapter {
    top 0
  }
  .menu {
    top 50%
  }
}
</style>
